# detection/file_menu.py

from PyQt5.QtWidgets import QAction, QFileDialog, QMessageBox
from PyQt5.QtCore import Qt, QObject, pyqtSignal
import os

class FileMenu(QObject):
    """
    文件菜单管理模块
    """
    open_image_signal = pyqtSignal(list)    # 打开图片信号，参数为文件路径列表
    open_video_signal = pyqtSignal(str)     # 打开视频信号
    open_camera_signal = pyqtSignal(int)    # 打开摄像头信号
    save_result_signal = pyqtSignal()       # 保存结果信号
    batch_process_signal = pyqtSignal(str)  # 批量处理信号，参数为文件夹路径
    exit_signal = pyqtSignal()              # 退出信号

    def __init__(self, parent):
        super().__init__(parent)
        self.parent = parent
        self.recent_files = []

        self._create_actions()

    def _create_actions(self):
        # 打开图片
        self.open_image_action = QAction("打开图片", self.parent)
        self.open_image_action.setShortcut("Ctrl+O")
        self.open_image_action.triggered.connect(self.open_image)

        # 打开视频
        self.open_video_action = QAction("打开视频", self.parent)
        self.open_video_action.setShortcut("Ctrl+V")
        self.open_video_action.triggered.connect(self.open_video)

        # 打开摄像头
        self.open_camera_action = QAction("打开摄像头", self.parent)
        self.open_camera_action.setShortcut("Ctrl+C")
        self.open_camera_action.triggered.connect(self.open_camera)

        # # 最近文件（动态生成菜单项时使用）
        # self.recent_files_actions = []

        # 保存检测结果
        self.save_result_action = QAction("保存检测结果", self.parent)
        self.save_result_action.setShortcut("Ctrl+S")
        self.save_result_action.triggered.connect(lambda: self.save_result_signal.emit())

        # 批量处理
        self.batch_process_action = QAction("批量处理", self.parent)
        self.batch_process_action.triggered.connect(self.batch_process)

        # 退出
        self.exit_action = QAction("退出", self.parent)
        self.exit_action.setShortcut("Ctrl+Q")
        self.exit_action.triggered.connect(lambda: self.exit_signal.emit())